package com.accesshollywood.viewFiltering;

import java.util.LinkedHashMap;

import com.accesshollywood.indexables.Indexed;

public class ViewFilter extends Indexed {// DefaultMutableTreeTableNode {
// public int idViewFilter;
	protected String	filterName;
	protected String	whereCondition;
	protected String	groupName;

	public ViewFilter() {
		super();
	}

	@Override
	public void initSQL() {
		setThat(this);
		tableName = "ViewFilterList";
		idColumnName = "idViewFilter";
	}
	
	@Override
	public int getId(){
		return this.hashCode();
	}
	
	public int toSQL(){
		return this.hashCode();
	}

	public ViewFilter(ViewFilterTemplate template) {
		this.setId(template.getId());
		filterName = template.filterName;
		whereCondition = template.whereCondition;
		groupName = template.viewFilterGroup.groupName;
	}

	public ViewFilter(ViewFilter newFilter) {
		super();
		this.setId(newFilter.getId());
		this.filterName = newFilter.filterName;
		this.whereCondition = newFilter.whereCondition;
	}

	public synchronized String getFilterName() {
		return filterName;
	}

	public synchronized void setFilterName(String filterName) {
		this.filterName = filterName;
	}

	public synchronized String getWhereCondition() {
		return whereCondition;
	}

	public synchronized void setWhereCondition(String whereCondition) {
		this.whereCondition = whereCondition;
	}

	public synchronized String getGroupName() {
		return groupName;
	}

	public synchronized void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((filterName == null) ? 0 : filterName.hashCode());
		result = prime * result + ((groupName == null) ? 0 : groupName.hashCode());
		result = prime * result + ((whereCondition == null) ? 0 : whereCondition.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		ViewFilter other = (ViewFilter) obj;
		if (filterName == null) {
			if (other.filterName != null)
				return false;
		} else if (!filterName.equals(other.filterName))
			return false;
		if (groupName == null) {
			if (other.groupName != null)
				return false;
		} else if (!groupName.equals(other.groupName))
			return false;
		if (whereCondition == null) {
			if (other.whereCondition != null)
				return false;
		} else if (!whereCondition.equals(other.whereCondition))
			return false;
		return true;
	}
}
